import { IDeployPanelItem } from "./IDeployPanelItem";
import { IToolTipItem } from "../../../../../com/mui/manager/IToolTipItem";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
import { ItemData } from "../../../resource/info/ItemData";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { BaseItem } from "../../common/BaseItem";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FilterConst } from "../../../../component/gconst/FilterConst";
type int = number;
//class DeployPanelItem
    
    export  class DeployPanelItem /* flash.display.Sprite */ implements IDeployPanelItem, IToolTipItem
    {
        constructor(arg1: int, arg2: Boolean=false, arg3: Boolean=false, arg4: string="", arg5: Boolean=false)
        {
            
            this._isNoBoarder = arg2;
            this._isJewel = arg3;
            this._tooltip = arg4;
            this._showName = arg5;
            this.panelIndex = arg1;
            this.createChildren();
            if (this._tooltip != "") 
            {
                ToolTipsManager.register(this);
            }
            return;
        }

        public get label(): string
        {
            return this._label;
        }

        public set label(arg1: string)
        {
            var loc1=NaN;
            var loc2=NaN;
            this._label = arg1;
            if (this._label.length != 2) 
            {
                if (this._label.length != 3) 
                {
                    if (this._label.length != 4) 
                    {
                        loc1 = 8;
                        loc2 = 12;
                    }
                    else 
                    {
                        this._label = this._label.substr(0, 2) + "\r" + this._label.substr(2);
                        loc1 = 7;
                        loc2 = 4;
                    }
                }
                else 
                {
                    loc1 = 2;
                    loc2 = 12;
                }
            }
            else 
            {
                loc1 = 8;
                loc2 = 12;
            }
            this.labelItem.x = loc1 - 2;
            this.labelItem.y = loc2 - 2;
            this.labelItem.htmlText = "<font color=\'#67C5DE\'><textformat leading=\'2\'>" + this._label + "</textformat></font>";
            return;
        }

        public set itemData(arg1: ItemData)
        {
            var loc1=null;
            if (arg1) 
            {
                this.labelItem.visible = false;
                ToolTipsManager.unregister(this);
            }
            else 
            {
                this.labelItem.visible = true;
                this.enabled = true;
                if (this._tooltip != "") 
                {
                    ToolTipsManager.register(this);
                }
            }
            this.item.itemData = arg1;
            this.item.amount = 0;
            if (this._showName) 
            {
                if (arg1) 
                {
                    loc1 = ColorConfig.instance.getItemColor(arg1.color).color;
                    this._nameLabel.htmlText = HTMLUtil.addColor("" + arg1.name + "", loc1);
                    if (!this._nameLabel.parent) 
                    {
                        this.addChild(this._nameLabel);
                    }
                }
                else 
                {
                    this._nameLabel.htmlText = "";
                    if (this._nameLabel.parent) 
                    {
                        this._nameLabel.parent.removeChild(this._nameLabel);
                    }
                }
            }
            else if (this._nameLabel.parent) 
            {
                this._nameLabel.parent.removeChild(this._nameLabel);
            }
            return;
        }

        public set amount(arg1: int)
        {
            if (this.item.itemData) 
            {
                this.item.amount = arg1;
                this.item.setAmountText(arg1);
            }
            else 
            {
                this.item.amount = 0;
                this.item.setAmountText(-1);
            }
            return;
        }

        public get amount(): int
        {
            return this.item.itemData ? this.item.amount : 0;
        }

        public get itemData(): ItemData
        {
            return this.item.itemData;
        }

        public set source(arg1: Object)
        {
            if (arg1) 
            {
                this.labelItem.visible = false;
            }
            else 
            {
                this.labelItem.visible = true;
                this.enabled = true;
            }
            this.item.source = arg1;
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            this.bodySprite = new Object /* flash.display.Sprite */();
            this.addChild(this.bodySprite);
            if (this._isNoBoarder) 
            {
                this.bodySprite.addChild(GlobalClass.getBitmap(ImagesConst.PackItemBg));
            }
            else 
            {
                loc1 = ResouceConst.getScaleBitmap(ImagesConst.equipment_boarder);
                loc1.x = -6;
                loc1.y = -6;
                this.bodySprite.addChild(loc1);
            }
            if (this._isJewel) 
            {
                loc2 = GlobalClass.getBitmap(ImagesConst.equipment_jewel_jewelbase);
                loc2.x = 3;
                loc2.y = 3;
                loc2.width = 32;
                loc2.height = 32;
                this.bodySprite.addChild(loc2);
            }
            this.labelItem = new GLabel();
            this.labelItem.height = 42;
            this.labelItem.width = 50;
            this.bodySprite.addChild(this.labelItem);
            this.item = new BaseItem();
            this.item.toolTipType = ItemData.ToolTipType_Forge;
            this.item.setSize(32, 32);
            this.item.isDragAble = false;
            this.item.isDropAble = true;
            this.item.isThrowAble = false;
            this.item.isShowLock = true;
            this.item.dropChecktFunction = this.canDropCheck;
            this.item.x = 3;
            this.item.y = 3;
            this.bodySprite.addChild(this.item);
            this._nameLabel = new GLabel();
            this._nameLabel.x = -20;
            this._nameLabel.y = 41;
            this._nameLabel.width = 78;
            this._nameLabel.height = 50;
            this._nameLabel.textField.wordWrap = true;
            this._nameLabel.setStyle("textFormat", new GTextFormat(null, null, null, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._nameLabel.htmlText = "";
            this._nameLabel.mouseEnabled = false;
            this._nameLabel.mouseChildren = false;
            return;
        }

        /* internal  */canDropCheck(arg1: BaseItem, arg2: BaseItem): Boolean
        {
            return false;
        }

        public set selected(arg1: Boolean)
        {
            this._selected = arg1;
            if (this._selected) 
            {
                this.bodySprite.filters = [FilterConst.itemChooseFilter];
            }
            else 
            {
                this.bodySprite.filters = [];
            }
            return;
        }

        public get selected(): Boolean
        {
            return this._selected;
        }

        public set enabled(arg1: Boolean)
        {
            this._enabled = arg1;
            if (arg1) 
            {
                this.bodySprite.filters = [];
            }
            else 
            {
                this.bodySprite.filters = [FilterConst.colorFilter2];
            }
            return;
        }

        public get enabled(): Boolean
        {
            return this._enabled;
        }

        public get toolTipData()
        {
            return this._tooltip;
        }

        public set toolTipData(arg1)
        {
            this._tooltip = arg1;
            return;
        }

        /* internal */ /* var */bodySprite: Object /* flash.display.Sprite */;

        public /* var */item: BaseItem;

        /* internal */ /* var */labelItem: GLabel;

        public /* var */posIndex: int;

        /* internal */ /* var */panelIndex: int=0;

        /* internal */ /* var */_selected: Boolean=false;

        /* internal */ /* var */_label: string;

        /* internal */ /* var */_isNoBoarder: Boolean;

        /* internal */ /* var */_isJewel: Boolean;

        /* internal */ /* var */_tooltip: string="";

        /* internal */ /* var */_showName: Boolean;

        /* internal */ /* var */_enabled: Boolean;

        /* internal */ /* var */_nameLabel: GLabel;
    }
